#ifndef BDPARA_H
#define BDPARA_H

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "Common.h"
#include "para-tr.h"
#include "para-pz.h"
#include "para-ad.h"

#pragma pack(push,1)

struct __attribute__ ((__packed__)) plVerisonInfo_r
{
    uint32_t uPriCode;
    uint32_t uDestbBaord;
    uint32_t uCompilerOs;
    uint32_t uOsUuid0;
    uint32_t uOsUuid1;
    uint32_t uOsUuid2;
    uint32_t uOsUuid3;
    uint32_t uDateDay;
    uint32_t uDateTime;
    uint32_t uPrjVersion;
    uint32_t uPrjMinVersion;
    uint32_t uVivadoVersion;
    uint32_t uVivadoMinVersion;
};

struct __attribute__ ((__packed__)) psVerisonInfo_r
{
    uint16_t uVersionMajor; 
    uint16_t uVersionMinor;
    uint16_t uVersionPatch;
    uint16_t uYear;
    uint16_t uMonth;
    uint16_t uData;
};

struct __attribute__ ((__packed__)) temperature_r
{
    float uPstemperature;
    float uPltemperature;
};

struct __attribute__ ((__packed__)) paramStatus_r
{
    uint16_t uInfo;//一般状态
    uint16_t uWarn;//告警状态
    uint16_t uError;//严重错误
};

struct __attribute__ ((__packed__)) hmc7044_r
{
    uint8_t uIdlsb;                //HMC7044 24位产品ID   (MSB:0x7a MIB:0x79 LSB:0x78) 
    uint8_t uIdmid;            
    uint8_t uIdmsb;            
    uint8_t uClock0Lose;          //HMC7044 时钟0丢失                    (0x7c) 1：丢失 0：正常
    uint8_t uClock1Lose;          //HMC7044 时钟1丢失                    (0x7c) 1：丢失 0：正常
    uint8_t uClock2Lose;          //HMC7044 时钟2丢失                    (0x7c) 1：丢失 0：正常
    uint8_t uClock3Lose;          //HMC7044 时钟3丢失                    (0x7c) 1：丢失 0：正常
    uint8_t uPll1Pll2LockSt;    //HMC7044 PLL1和PLL2锁定检测           (0x7d) 1：锁定 0：失锁
    uint8_t uClockPhaseOut;      //HMC7044 时钟输出相位状态              (0x7d) 1：相位稳定 0：相位不稳定
    uint8_t uSysrefSyncSt;      //HMC7044 SYSREF同步状态               (0x7d) 1：不同步 0：同步
    uint8_t uRegisters7e;         //HMC7044 警报回读 查表 ：0x7e
    uint8_t uPll1ClkinValid;        //HMC7044 PLL1有效CLKIN0/CLKIN0输入    (0x82) 指示当前使用的CLKINx/CLKINx输入
    uint8_t uRegisters85;         //HMC7044 PLL1状态查询 查表：0x85
    uint8_t uRegisters8f;         //HMC7044 PLL2状态查询 查表：0x8f
};

struct __attribute__ ((__packed__)) si5341_r
{                                   //功能                         //参数含义
    uint8_t uClockSelect;         //reg 0x21  //Si5341时钟输入选择方式控制            0：管脚控制  1：寄存器控制
    uint8_t uReferEnceinx;        //reg 0x21  //Si5341时钟输入控制                    0：IN0 1：IN1 2：IN2 3：晶振（XA/XB）
    uint8_t uSpiLines;            //reg 0x2b  //Si5341SPI模式设置                    0: 4线SPI 1:  3线SPI
    uint8_t uLosStat;             //reg 0x2c  //Si5341配置LOS1(不包括XAXB输入)        0:禁用LOS 1：使能LOS
    uint8_t uXaxbInDisableLos;  //reg 0x2c  //Si5341配置LOS2(输入为XAXB时,禁用LOS)   0:无效 1：输入为XAXB，禁用LOS
    uint8_t uIdLsb;               //reg 0x02-3//Si5341产品家族编码低位                     4位产品家族编码，每4位对应1个数字
    uint8_t uIdMsb;               //reg 0x02-3//Si5341产品家族编码高位                     4位产品家族编码，每4位对应1个数字
    uint8_t uSpeed;                //reg 0x04  //Si5341器件速度等级                     0：等级A 1：等级B 2：等级C 3：等级D  
    uint8_t uVersion;              //reg 0x05  //Si5341器件版本                         0：版本A 1：版本B
    uint8_t uInxLose;             //reg 0x0d  //Si5341告警信息                         0：FB_IN没有输入 1：IN0没有输入 2：IN1没有输入 3：IN2没有输入
    uint8_t uStatInfo;            //reg 0x0c  //Si5341状态信息                         bit0：处于校准状态 bit1：XA管脚无信号状态 bit2：鉴频鉴相器没有从XAXB/IN0/IN1/IN2收到信息 bit3:DSPLL失锁 bit5：SMBus超时
};


struct __attribute__ ((__packed__)) cvSXParam_r
{
    //a
    uint16_t m_vMgtaVcc0v9;//ZU9CG_MGTAVCC_0V9电源电压/电流
    uint16_t m_iMgtaVcc0v9;
    uint16_t m_vMgtaVtt1v2;//ZU9EG_MGTAVTT_1V2电源电压/电流
    uint16_t m_iMgtaVtt1v2;
    uint16_t m_vVccAux1v8;//ZU9EG_VCCAUX_1V8辅电压1.8V电源电压/电流
    uint16_t m_iVccAux1v8;
    //b
	uint16_t m_VVccInt0v85;//ZU9CG内核0.85V电源电压/电流
    uint16_t m_IVccInt0v85;
    uint16_t m_vVcc1v3;//VDDR4_1V2电源电压/电流
    uint16_t m_iVcc1v3;

    //c
    uint16_t m_vVcc5v0;//ZU9CG_VCC_5V0电源电压/电流
    uint16_t m_iVcc5v0;
    uint16_t m_vVout5v6;//VCC_5V6电源电压/电流
    uint16_t m_iVout5v6;
    uint16_t m_v70443v6;//HMC7044_3V6电源电压/电流
    uint16_t m_i70443v6;
    //e
    uint16_t m_vVcc3v3;//VCC_3V3电源电压、电流
    uint16_t m_iVcc3v3;
    uint16_t m_vVcc2v5;//VCC_2V5电源电压、电流
    uint16_t m_iVcc2v5;
    uint16_t m_vDdr1v2;//DDR_1V2电源电压、电流
    uint16_t m_iDdr1v2;
};

struct __attribute__ ((__packed__)) sxkTemperature_r
{
    float uPstemperature;
    float uPltemperature;
    float uSensorTemp; //-40 - 125	°C(0.1°C)温度有符号整型，小端
    float uSensorHumidity; //0-100%(1.5%RH)
};



struct __attribute__ ((__packed__)) sxkLvdsError_r
{
    uint32_t e_tr0_crc_cnt;     //TR0 CRC错误计数--误码值
    uint32_t e_tr0_timeout_cnt; //TR0 响应超时计数--丢包值
    uint32_t e_tr1_crc_cnt;     //TR1 CRC错误计数
    uint32_t e_tr1_timeout_cnt; //TR1 响应超时计数
    uint32_t e_pz_crc_cnt;      //频综 CRC错误计数
    uint32_t e_pz_timeout_cnt;  //频综 响应超时计数
    uint32_t e_hsi_status;      //高速接口状态
    uint32_t e_lvds_send_cnt;   //LVDS发送数据计数
    uint32_t e_ad_ch0_lost_cnt; //AD光纤通道0掉线计数
    uint32_t e_ad_ch1_lost_cnt; //AD光纤通道1掉线计数
    uint32_t e_ad_ch2_lost_cnt; //AD光纤通道2掉线计数
    uint32_t e_ad_ch3_lost_cnt; //AD光纤通道3掉线计数
    uint32_t e_ad_ch4_lost_cnt; //AD光纤通道4掉线计数
    uint32_t e_ad_ch5_lost_cnt; //AD光纤通道5掉线计数
    uint32_t e_ad_ch6_lost_cnt; //AD光纤通道6掉线计数
    uint32_t e_ad_ch7_lost_cnt; //AD光纤通道7掉线计数
    uint32_t e_ad_ch0_err_cnt;  //AD光纤通道0帧错误计数
    uint32_t e_ad_ch1_err_cnt;  //AD光纤通道1帧错误计数
    uint32_t e_ad_ch2_err_cnt;  //AD光纤通道2帧错误计数
    uint32_t e_ad_ch3_err_cnt;  //AD光纤通道3帧错误计数
    uint32_t e_ad_ch4_err_cnt;  //AD光纤通道4帧错误计数
    uint32_t e_ad_ch5_err_cnt;  //AD光纤通道5帧错误计数
    uint32_t e_ad_ch6_err_cnt;  //AD光纤通道6帧错误计数
    uint32_t e_ad_ch7_err_cnt;  //AD光纤通道7帧错误计数
    uint32_t e_interfece_ch0_lost_cnt;     //接口卡光纤通道0掉线计数
    uint32_t e_interfece_ch1_lost_cnt;     //接口卡光纤通道1掉线计数
    uint32_t e_interfece_ch2_lost_cnt;     //接口卡光纤通道2掉线计数
    uint32_t e_interfece_ch3_lost_cnt;     //接口卡光纤通道3掉线计数
};

struct __attribute__ ((__packed__)) gpsSensor_r
{
    uint16_t temp;      //温度有符号整型，小端
    uint16_t humidity;//湿度
    uint16_t air_pressure_h;
    uint16_t air_pressure_l;
};

struct __attribute__ ((__packed__)) gps
{
    uint16_t m_hour;
    uint16_t m_min;
    uint16_t m_sec;
    uint8_t m_decimal;//小数点
    uint16_t m_dsec;//小数点后2位
    uint8_t m_validFlag;//A为有效V为无效，定位有效标志位
    uint16_t m_dLatitude;//纬度d
    uint16_t m_mLatitude;//纬度m
    uint8_t m_latiDecimal;//小数点
    uint8_t m_mmLatitude0;//纬度mm
    uint8_t m_mmLatitude1;//纬度mm
    uint8_t m_mmLatitude2;//纬度mm
    uint8_t m_mmLatitude3;//纬度mm
    uint8_t m_mmLatitude4;//纬度mm
    uint8_t m_latiLocal;//纬度方向N北纬S南纬
    uint8_t m_dLongitude0;//经度d
    uint8_t m_dLongitude1;//经度d
    uint8_t m_dLongitude2;//经度d
    uint16_t m_mLongitude;//经度m
    uint8_t m_mLongDecimal;//经度小数点
    uint8_t m_mmLongitude0;//经度mm
    uint8_t m_mmLongitude1;//经度mm
    uint8_t m_mmLongitude2;//经度mm
    uint8_t m_mmLongitude3;//经度mm
    uint8_t m_mmLongitude4;//经度mm
    uint8_t m_longLocal;//经度方向E为东经W为西经
    uint8_t m_altitude0;//高度
    uint8_t m_altitude1;//高度
    uint8_t m_altitude2;//高度
    uint8_t m_altitude3;//高度
    uint8_t m_altitude4;//高度
    uint8_t m_altitude5;//高度
    uint32_t m_baseline; //32bit little-endian 基线距离
    uint32_t m_baselinePrec;//32bit little-endian 基线距离精度
    uint32_t m_azimuth;//32bit little-endian  方位角
    uint32_t m_azimuthPrec;//32bit little-endian  方位角精度
    uint16_t m_day;
    uint16_t m_month;
    uint16_t m_year;
    struct gpsSensor_r m_sensor0;
    struct gpsSensor_r m_sensor1;
    struct gpsSensor_r m_sensor2;
    struct gpsSensor_r m_sensor3;
    struct gpsSensor_r m_sensor4;
};

// //数据解析结构体
struct gnssUpdateRtu_r
{
    uint16_t fen[12];                   //风扇1-12速度反馈，占空比10%（19500-21200）占空比90%
    uint16_t utc_time[9];               //世界时	UTF-8	HHMMSSSSS(时分秒)              
    uint16_t location_status;           // 定位是否有效	UTF-8	A(有效) ro V(无效)
    uint16_t latitude[10];              // 纬度	UTF-8	度十进制表示法：40.712800
    uint16_t latitude_latitude;         // 纬度半球	UTF-8	S(南纬) ro N(北纬)
    uint16_t longitude[11];             // 经度	UTF-8	度十进制表示法：74.006000
    uint16_t longitude_latitude;        // 经度方向	UTF-8	E(东经) ro W(西经)
    uint16_t alt[6];                    // 海拔高度	UTF-8	单位：m
    int relPosLength;                   //两天线之间的距离
    int accLength;                      // 两天线之间的距离精度
    int relPosHeading;                  // 方位角
    int accHeading;                     // 方位角精度
    uint16_t utc_data[6];               // 世界日期	UTF-8	YYMMDD(年月日)
    short int sht35_temp;               // 温度	-20至80	单位：℃
    short int sht35_humi;               // 湿度	0至100	单位：%
    uint16_t board_5v_voltage;         // 5V电压	0至12000	单位：mV
    uint16_t board_3v3_voltage;          // 3.3V电压	0至5000	单位：mV
    uint16_t board_12V_voltage;         // 12V电压	0至3300	单位：mV
    uint16_t board_5v_current;         // 5V电流	0至2000	单位：mA
    uint16_t board_3v3_current;          // 3.3V电流	0至2000	单位：mA
    uint16_t board_12v_current;        // 12V电流	0至2000	单位：mA
    
};

//组件状态
struct __attribute__ ((__packed__)) subSXStatus_r
{
    uint16_t timing_status;
    uint16_t Timing_Generator_status;//1:锁定，可以执行时序下发。0：未锁定，拒绝时许下发并上报
};



struct __attribute__ ((__packed__)) sxk
{
    struct psVerisonInfo_r psVerisonInfo;
    struct plVerisonInfo_r plVerisonInfo;
    struct cvSXParam_r cvParam;
    struct sxkTemperature_r tempParam;

    struct hmc7044_r hmc7044;
    struct si5341_r si5341;
    struct subSXStatus_r subSt;
    struct sxkLvdsError_r lvdsStatus; 
    struct gnssUpdateRtu_r gnssUpdate;
} ;





struct __attribute__ ((__packed__)) cooling 
{
    uint16_t uFlow;//供液流量
    uint8_t uPressure;//供液压力
    uint8_t uOutTemp;//供液温度
    uint8_t uBackTemp;//回液温度
    uint8_t uWorkMode;//模式状态
    uint8_t uSourceStatus;//液冷源状态
    uint8_t uWorkStatus;//工作状态
    uint8_t uFault1;//故障 1
    uint8_t uFault2;//故障 1
};


struct nbj
{
    uint16_t not_user;
};

struct bdpara
{
    /* data */
    tr trpara[2];
    struct ad adpara[2];
    struct sxk sxkpara;
    // struct nbj nbjpara;
    pz pzpara;
    // struct gps gpspara;
};

#pragma pack(pop)

#endif